﻿package app.model.proxy
{	
    import app.facade.App;   
	import app.facade.BApp;
	import app.facade.CApp;
	import app.facade.EApp;	
	import flash.external.ExternalInterface;
	import org.osflash.thunderbolt.Logger;
    
    import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;
	/**
	 * @author hungconcon
	 */
    public class ExternalProxy extends Proxy implements IProxy
    {
        public static const NAME:String = "ExternalProxy";
		private var app:AppProxy;
        public function ExternalProxy( ){
            super( NAME );	
        }
		override public function onRegister():void {
			super.onRegister();
		}
		public function init():void {
			if ( ExternalInterface.available ){
				ExternalInterface.addCallback( BApp.mouseWheel	,		mouseWheel);
				ExternalInterface.addCallback( BApp.showError	,		showError);
			}
		}
		
		/**
		 * throug error to here!
		 * @param	string
		 */
		private function showError(string:String):void {
			sendNotification(App.SHOW_ERROR, string);
		}
		private function mouseWheel(value:String):void {
			if (value == '') return;
			sendNotification(EApp.WHEEL_SCROLL, value);
		}
		/**
		 * call to javascript open Mail
		 * @param	value
		 */
		
		public function openMail(value:String):void {
			//callOutWithOne(CApp.openMail, value);
		}
		
		public function openRegister(value:String = ""):void {
			callOutWithOne(CApp.openRegister, value);
		}
		
		public function closeRegister(value:String = ""):void {
			callOutWithOne(CApp.closeRegister, value);
		}

		/***********************************************************
		 * keep in touch!
		 * @param	value as userid
		 */
		private function callOut(value:String, ... arg):void { 
			if (ExternalInterface.available) ExternalInterface.call(value, arg);  
		}
		private function callOutWithOne(value:String, data:String):void { 
			if (ExternalInterface.available) ExternalInterface.call(value, data);  
		}
    }
}